public class maxSum {
    public static void main(String[] args) {
        //int nums[] = { 1, -2, 3, 5, -1 }; // 测试用例1,最大值8
        //int nums[] = { 1, -2, 3, -8, 5, 1 }; // 测试用例2,最大值6
        //int nums[] = { 1, -2, 3,-2, 5, 1}; // 测试用例3,最大值7
        int nums[] = { }; // 测试用例4,错误
        maxSum maxSum=new maxSum();
        maxSum.findMaxArray(nums);
    }

    public  void findMaxArray(int[] array){
        if (array == null || array.length == 0) {
            return ;
        }
        int maxSum = Integer.MIN_VALUE;
        int currentSum = 0;
        for (int i = 0; i < array.length; i++) {
            if (currentSum < 0) {
                currentSum = array[i];
            }else {
                currentSum += array[i];
            }
            maxSum = Math.max(maxSum, currentSum);
        }
        System.out.println(maxSum);
    }

}
